source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

"set diffexpr=MyDiff()
"function MyDiff()
"  let opt = '-a --binary '
"  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
"  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
"  let arg1 = v:fname_in
"  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
"  let arg2 = v:fname_new
"  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
"  let arg3 = v:fname_out
"  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
"  if $VIMRUNTIME =~ ' '
"    if &sh =~ '\<cmd'
"      if empty(&shellxquote)
"        let l:shxq_sav = ''
"        set shellxquote&
"      endif
"      let cmd = '"' . $VIMRUNTIME . '\diff"'
"    else
"      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
"    endif
"  else
"    let cmd = $VIMRUNTIME . '\diff'
"  endif
"  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
"  if exists('l:shxq_sav')
"    let &shellxquote=l:shxq_sav
"  endif
"endfunction

" echo ">^.^<i

" Basic settings -----------------------{{{
filetype on
filetype indent on
let mapleader=" "
set nobackup
set noswapfile
set noundofile
set nu
set nowrap
set tabstop=4
set shiftwidth=4
set expandtab
" set encoding=utf-8
set fileencodings=utf-8,Unicode,gbk,cp-936
set fileencoding=utf-8
set foldlevelstart=0
"}}}

" Statusline settings ----------------------------{{{
set laststatus=2
set statusline=%F  "  %F 完整文件路径名
set statusline+=%m "  %m 当前缓冲被修改标记 
set statusline+=%r "  %r 当前缓冲只读标记
set statusline+=%h "  %h 帮助缓冲标记 
set statusline+=%w "  %w 预览缓冲标记
set statusline+=%= " move to the right
set statusline+=\  " space as separator
set statusline+=[ft=%Y] "  %Y 文件类型
set statusline+=\  " space as separator
set statusline+=%{\"[fenc=\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\"+\":\"\").\"]\"} " file encoding
set statusline+=\  " space as separator 
set statusline+=[ff=%{&ff}] "  %{&ff} 显示文件类型
set statusline+=\  " space as separator 
set statusline+=[asc=%03.3b] "  %b ASCII值
set statusline+=\  " space as separator 
set statusline+=[hex=%02.2B] "  %B十六进制值
set statusline+=\  " space as separator 
set statusline+=[pos=%04l,%04v] "  %l 行数 %v 列数
set statusline+=[%p%%] "  %p 当前行数占总行数的的百分比
set statusline+=\  " space as separator 
set statusline+=[len=%L] "  %L 总行数
"}}}

"Mappings ---------------------{{{
nnoremap w= :resize +3<cr>
nnoremap w- :resize -3<cr>
nnoremap w, :vertical resize -3<cr>
nnoremap w. :vertical resize +3<cr>
inoremap <c-d> <esc>ddi
nnoremap <c-d> dd
inoremap <c-u> <esc>viwUi
nnoremap <c-u> viwU
nnoremap H ^
nnoremap L $
vnoremap y y`>
inoremap jk <esc>
nnoremap <tab> <c-w>w
"}}}

" force to learn musucle mapping ----------------------{{{
inoremap <left> <nop>
inoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
nnoremap <up> <nop>
nnoremap <down> <nop>
inoremap <esc> <nop>
"}}}

" Edit and Source vimrc file mapping ------------------{{{
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
"}}}

" Sround with text mapping ---------------------------------{{{
nnoremap <leader>" viw<esc>i"<esc>bi"<esc>lel
vnoremap <leader>" <esc>`<i"<esc>`>a"<esc>
nnoremap <leader>' viw<esc>i'<esc>bi'<esc>lel
vnoremap <leader>' <esc>`<i'<esc>`>a'<esc>
nnoremap <leader>[ viw<esc>i]<esc>bi[<esc>lel
vnoremap <leader>[ <esc>`<i[<esc>`>a]<esc>
nnoremap <leader>{ viw<esc>i}<esc>bi{<esc>lel
vnoremap <leader>{ <esc>`<i{<esc>`>a}<esc>
nnoremap <leader>< viw<esc>i><esc>bi<<esc>lel
vnoremap <leader>< <esc>`<i<<esc>`>a><esc>
"}}}

" Some iabbreviation ----------------{{{
iabbr @@ luquanwei@foxmail.com
iabbr ccopy copyright luquanwei, all rights reserved.
"}}}

" Java file settings -------------------{{{
augroup javagroup
    autocmd!
    autocmd FileType java nnoremap <buffer> <localleader>c I//<esc>
augroup END
"}}}

" Javascript file settings --------------{{{
augroup javascriptgroup
    autocmd!
    autocmd FileType javascript nnoremap <buffer> <localleader>c I//<esc>
    autocmd FileType javascript :iabbrev <buffer> iff if ()<left>
augroup END
"}}}

" Python file settings----------------------{{{
augroup pythongroup
    autocmd!
    autocmd FileType python nnoremap <buffer> <localleader>c I#<esc>
    autocmd FileType python     :iabbrev <buffer> iff if:<left>
augroup END
"}}}

" Markdown file settings---------------------{{{
augroup markdowngroup
    autocmd!
    autocmd FileType markdown onoremap <buffer> ih :<c-u>execute "normal! ?^==\\+$\r:nohlsearch\rkvg_"<cr>
    autocmd FileType markdown onoremap <buffer> ah :<c-u>execute "normal! ?^==\\+$\r:nohlsearch\rg$vk0"<cr>
augroup END
"}}}

" Vimscript file settings -------------------{{{
augroup vimgroup
    autocmd!
    autocmd FileType vim setlocal foldmethod=marker
augroup END
" }}}
